package gmu.swe.project.tracker;

import gmu.swe.project.peer.PeerInfo;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/**
 * Class is used to test the Tracker  - This test focuses on registering a Peer.
 * @author Christina Bradbury
 *
 */
public class TrackerTester1 {
	
	public static void main(String[] args) {
		try {
			
		Socket socketConnection = new Socket("42.0.3.186", 10399);
		
        //output stream to write to the server
        ObjectOutputStream oos = new ObjectOutputStream(socketConnection.getOutputStream());
        
        //create a PeerInfo object
        PeerInfo info = new PeerInfo();
        info.setId("1");
        info.setIpAddress("127.196.1.1");
        info.setPort(2);
        info.addFile("testFile1");
        info.setWorkload(new Integer(1));
        
        //send the object to the Tracker
        oos.writeObject(info);
        
        //incoming stream to receive from the server
        ObjectInputStream ois = new ObjectInputStream(socketConnection.getInputStream());
        
        //get back the ACK
        String ack = (String)ois.readObject();
        
        System.out.println("Tracker Tester 2 :: ACK from Server: " + ack );
        
        //close the streams
        oos.close();
        ois.close();
        socketConnection.close();	
        System.out.println("Client closed");
		}
		catch (Exception ex) {
			System.out.println("Error in TrackerTester1: " + ex);
		}
	}
}
